package fakeworker;

import java.util.HashMap;
import java.util.Map;

import phonebookitem.PhoneBookItem;
import iphoneworker.IPhoneWorker;

public class FakeWorker implements IPhoneWorker{
	private static Map<Long, PhoneBookItem> PhoneBook = null;
	private static final int size = 10;
	
	public FakeWorker()
	{
		PhoneBook = new HashMap<Long,PhoneBookItem>();
		
		for (long i = 0; i < size; i++) {
			PhoneBookItem item = new PhoneBookItem();
			item.setEmail("email"+i);
			item.setFirstName("firstName"+i);
			item.setHomeAddres("homeAddres"+i);
			item.setId(i);
			item.setLastName("lastName"+i);
			item.setName("name"+i);
			item.setPhone1("phone1"+i);
			item.setPhone2("phone2"+i);
			item.setPhone3("phone3"+i);
			PhoneBook.put(i, item);
		}
	}
	
	public FakeWorker(PhoneBookItem [] items)
	{
		PhoneBook = new HashMap<Long,PhoneBookItem>();
		for (int i = 0; i < items.length; i++) {
			PhoneBook.put(Long.valueOf(i), items[i]);
		}
	}
	
	@Override
	public PhoneBookItem[] GetAll() {
		return PhoneBook.values().toArray(new PhoneBookItem[PhoneBook.size()]);
	}

	@Override
	public void Additem(PhoneBookItem item) {
		PhoneBook.put(Long.valueOf(PhoneBook.size()+1), item);		
	}

	@Override
	public Boolean Delete(long id) {
		PhoneBook.remove(Long.valueOf(id));
		return null;
	}

	@Override
	public PhoneBookItem EditItem(PhoneBookItem item) {
		PhoneBook.put(Long.valueOf(item.getId()), item);
		return PhoneBook.get(item.getId());
	}

	@Override
	public PhoneBookItem GetById(long id) {
		return PhoneBook.get(id);
	}
}
